Duplikovani BLOBu po vlozeni dat

Otázka od: Karel Kimes

10. 12. 2002 14:21

ahoj,
narazil sem na velice zvlastni chovani MySQL ve spojeni s komp. Zeos a D6
update pack 2.

Definice tabulky:

mysql> describe blob_test;
+-------+----------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+----------------+
| ID | int(11) | | PRI | NULL | auto_increment |
| blob_ | longblob | | | NULL | |
+-------+----------+------+-----+---------+----------------+
2 rows in set (0.00 sec)



kod:

procedure WriteToDB(Query : TZMySqlQuery; Field : TField; Data : OleVariant);
var
   blob_s : TBlobStream;
   p : pointer;
begin
   blob_s := TBlobStream(CreateBlobStream(Field, bmWrite));
   try
     p := VarArrayLock(Data)
       try
         blob_s.Write(p^, VarArrayHighBound(Data, 1));
       finally
         VarArrayUnlock(Data)
       end;
   finally
     blob_s.free;
   end;
end;


...
...
...
   Query.Sql.Clear;
   Query.Sql.Add('SELECT blob_ FROM blob_test WHERE ID = ' + IntToStr(ID));
   Query.RequestedLive := true;
   Query.Open;

// ted mam Query.RecordCount = 1
// a provedu tedy:

   Query.Edit;
   WriteToDB(Query, Field, Data);
   Query.Post;

...
...
...

Predpokladejme nyni prazdnou tabulku. Vlozim zaznam (s polem BLOB = NULL) a
provedu nacteni tohoto zaznamu SELECTem (viz. kod). Procedure WriteToDB
zapise obsah variantniho pole do streamu.
Svete div se zaznam je tam a rekneme, ze data mela delku 10B.

Nyni provedeme vlozeni dalsiho zaznamu (opet s polem BLOB = NULL) a
zapiseme procedurou WriteToDB dalsi data, nyni rekneme 20B.

A hle!!! Najednou maji BLOBy v OBOU! zaznamech delku 20B a obsahuji stejny
data!!! What's going on?

prosim otestujte to, zkuste to, ja si s tim proste nevim rady.
Zeos beta 5.3.0 build 6
Delphi 6 update pack 2
MySQL 3.23.51-nt
WinXP build 2600